package com.psp.web.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.stereotype.Repository;

import com.psp.web.model.InvoiceHeaderBean;
import com.psp.web.persist.dao.InvoiceHeaderDao;

@Repository
public class InvoiceHeaderImpl extends BaseImpl implements InvoiceHeaderDao {

	protected static final String NAME_SPACE = NAME_SPACE_HEADER + ".InvoiceHeaderMapper";

	@Override
	public InvoiceHeaderBean selectById(String id) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectById", id);
	}

	@Override
	public InvoiceHeaderBean selectById(String id, String uid) {
		Map<String, Object> where = new HashMap<>();
		where.put("id", id);
		where.put("uid", uid);
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectByIdAndUid", where);
	}

	@Override
	public List<InvoiceHeaderBean> selectByIds(Set<String> ids) {
		Map<String, Object> where = new HashMap<>();
		where.put("ids", ids);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectByIds", where);
	}

	@Override
	public int deleteById(String id, String uid) {
		Map<String, Object> where = new HashMap<>();
		where.put("id", id);
		where.put("uid", uid);
		return sqlSessionTemplate.delete(NAME_SPACE + ".deleteById", where);
	}

	@Override
	public int insert(InvoiceHeaderBean bean) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insert", bean);
	}

	@Override
	public int update(InvoiceHeaderBean bean) {
		return sqlSessionTemplate.update(NAME_SPACE + ".update", bean);
	}

	@Override
	public int selectCount(String uid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount", uid);
	}

	@Override
	public List<InvoiceHeaderBean> selectList(int page, int pageSize, String uid) {
		Map<String, Object> where = new HashMap<>();
		where.put("start", page * pageSize);
		where.put("length", pageSize);
		where.put("uid", uid);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", where);
	}

}
